package com.cskaoyan.market.util;

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @NAME: GetReqBodyUtil
 * @DESCRIPTION: 获取请求体文本内容
 * @DATE: 2023/5/8 12:16
 * @AUTHOR: 刘超
 */
public class GetReqBodyUtil {
    public static String getRequestBody(HttpServletRequest req) throws IOException {
        ServletInputStream inputStream = req.getInputStream();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        IOUtils.copy(inputStream, byteArrayOutputStream);
        return byteArrayOutputStream.toString("utf-8");
    }

}
